package com.zhuiYun.project.api.customer.mapper;

import cn.hutool.json.JSONObject;
import com.zhuiYun.project.common.mapper.BaseMapper;
import com.zhuiYun.project.api.customer.entity.MessageEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * LC: 2023-04-03 14:46
 */
@Mapper
public interface MessageMapper extends BaseMapper<MessageEntity> {
    /**
     * 查询会话列表
     * @param id
     * @return
     */
//    @Select("SELECT * FROM message WHERE session_id = #{id} ORDER BY send_time desc limit 1")
//    MessageEntity readMessageBySessionId(Integer id);

    /**
     * 查询聊天记录
     * @param sessionId
     * @return
     */
    @Select("SELECT m.*,u.avatar_url FROM message m,user u WHERE m.sender_id = u.id and m.sender_id=u.id and friend_id = #{sessionId} ORDER BY m.send_time ASC")
    List<JSONObject> readMessage(Long sessionId);
}
